#include "protocols/Ftp_Data.h"
#include "utilities/ReadablePacket.h"
#include "protocols/ProtocalCode.h"
#include "protocols/ProtocalPool.h"
#include "protocols/ShowableItem.h"
#include "utilities/utilities.h"

REGISTER_PROTOCOL(Ftp_DataProtocal)

QString Ftp_DataHeader::getSummary() const
{
	QString &str = byteToString((const char *) mData, getHeaderLength() - 2);
	str.replace("\r\n", "\\r\\n");
	return str;
}

void Ftp_DataHeader::toShowableItems(ShowableItem* root) const
{
	int pos = mPos;

	ShowableItem* proto = createProtocalItem("FTP Data", pos, getHeaderLength());
	root->pushChild(proto);

	ShowableItem* tmp =createItem("FTP Data", getFtpData(), pos, getHeaderLength() - 2);
	proto->pushChild(tmp);
}


Ftp_DataProtocal::Ftp_DataProtocal() : Protocol(FTP_DATA,QString("FTP Data"))
{
	shared_ptr<AppProtocolProperty> prop = make_shared<AppProtocolProperty>();
	prop->mDefaultPort.push_back(20);
	mInfo = prop;
}

boost::shared_ptr<PacketHeader> 
Ftp_DataProtocal::analyzeProc(boost::shared_ptr<ReadablePacket> packet,int low,int high,boost::shared_ptr<Protocol>& tip)
{
	boost::shared_ptr<Ftp_DataHeader> header(make_shared<Ftp_DataHeader>(Ftp_DataProtocal_register.m_Instance,packet->getData(),low,high - low + 1));

	tip.reset();

	return header;
}